﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF_Encrypt_Demo
{
    public struct PointData
    {
        public double X { get; set; }
        public double Y { get; set; }
        public double Speed { get; set; }

        public PointData(double x, double y, double speed)
        {
            X = x;
            Y = y;
            Speed = speed;
        }

        public byte[] ToBytes()
        {
            List<byte> bytes = new List<byte>();
            bytes.AddRange(BitConverter.GetBytes(X));
            bytes.AddRange(BitConverter.GetBytes(Y));
            bytes.AddRange(BitConverter.GetBytes(Speed));
            return bytes.ToArray();
        }

        public static PointData FromBytes(byte[] bytes)
        {
            double x = BitConverter.ToDouble(bytes, 0);
            double y = BitConverter.ToDouble(bytes, 8);
            double speed = BitConverter.ToDouble(bytes, 16);
            return new PointData(x, y, speed);
        }
    }
}
